package com.magpiebridge.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.magpiebridge.dao.UserDao;
import com.magpiebridge.pojo.User;
import com.magpiebridge.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;


    @Override
    public List<User> getAllUser() {
        return userDao.selectList(null);
    }

    @Override
    public User getUserById(Integer id) {
        return userDao.selectById(id);
    }


    @Override
    public boolean updateUserState(Integer id) {
        User user = getUserById(id);
        if (user == null) {
            return false; // 用户不存在，返回失败
        }

        boolean state = user.getState(); // 获取当前状态值
        user.setState(!state); // 将状态取反

        int result = userDao.updateUser(user);
        return result > 0; // 更新用户状态并返回更新结果
    }

    @Override
    public int updateUser(User user) {
        return userDao.updateById(user);
    }


    @Override
    public int deleteUser(Integer id) {
        return userDao.deleteById(id);
    }

    @Override
    public  int insertUser(User user){
        return userDao.insert(user);
    }


}
